package config

import (
	"common/helper"
	"database/sql"
)

/*
三方游戏配置
*/

type CfgThirdGameItem struct {
	platformId string  `json:"platformId" db:"platformId" cbor:"platformId"`
	taxSwitch  int     `json:"taxSwitch" db:"taxSwitch" cbor:"taxSwitch"`
	taxRate    float64 `json:"taxRate" db:"taxRate" cbor:"taxRate"`
}
type CsThirdGameCfg struct{}

var cfgThirdGameList []CfgThirdGameItem

func (that *CsThirdGameCfg) GetCfg() []CfgThirdGameItem {
	return cfgThirdGameList
}

func (that *CsThirdGameCfg) removeAllCfg() {
	cfgThirdGameList = []CfgThirdGameItem{}
}

func GetThirdGameTaxRate(platformId string) float64 {
	if !IsThirdOpenTax(platformId) {
		return 0.00
	}
	for _, value := range cfgThirdGameList {
		if value.platformId == platformId {
			return value.taxRate
		}
	}

	return 0.00
}
func IsThirdOpenTax(platformId string) bool {
	for _, value := range cfgThirdGameList {
		if value.platformId != platformId {
			continue
		}
		if value.taxSwitch == 0 {
			return false
		} else {
			return true
		}

	}

	return false
}

func ThirdGameCfgRemove() {
	cfgThirdGameList = []CfgThirdGameItem{}
}

func ThirdGameCfgSetRow(rows *sql.Rows) {
	var tVal CfgThirdGameItem
	var err error
	err = rows.Scan(&tVal.platformId, &tVal.taxSwitch, &tVal.taxRate)
	if err != nil {
		helper.InfoLog("ThirdGameCfgSetRow,scan err")
		return
	}

	cfgThirdGameList = append(cfgThirdGameList, tVal)
}
